package com.greate.shiro.springbootshirodemo.config;

import lombok.SneakyThrows;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.apache.shiro.crypto.hash.Sha384Hash;
import org.springframework.stereotype.Component;

/**
 * @author Administrator
 */
@Component
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {
	@SneakyThrows
	@Override
	public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {

		TokenInfo unSign = JwtTokenUtils.unsign(token.getPrincipal().toString(), TokenInfo.class);
		assert unSign != null;
		String psd = encrypt(String.valueOf(unSign.getPassword()));
		String myPsd = (String) info.getCredentials();
		//将传进来的密码进行加密的方法
//        return psd.equals(myPsd);
		return true;
	}

	public static String encrypt(String data) {
		return new Sha384Hash(data).toBase64();
	}


}
